import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { Table, Row, Col, Button } from 'antd';
import {
  WeaErrorPage,
  WeaTools,
  WeaLocaleProvider,
} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
@inject('newsStore')

@observer
class Main extends React.Component {
  componentDidMount() {
  }
  componentWillReceiveProps() {
  }
  componentWillUnmount() {
  }

  render() {
    const { newsStore } = this.props;
    const { contentDatas: { attachList, content } } = newsStore;
    const attachListCon = toJS(attachList),
bool = toJS(attachList).length !== 0;
    const labels = {
      xls: 'icon-coms-excel2',
      xlsx: 'icon-coms-excel2',
      doc: 'icon-coms-word2',
      docx: 'icon-coms-word2',
      pdf: 'icon-coms-pdf2',
      ppt: 'icon-coms-ppt2',
      pptx: 'icon-coms-ppt2',
      html: 'icon-coms-html2',
      htm: 'icon-coms-html2',
      rar: 'icon-coms-rar2',
      zip: 'icon-coms-rar2',
      png: 'icon-coms-pic2',
      jpg: 'icon-coms-pic2',
      jpge: 'icon-coms-pic2',
      bmp: 'icon-coms-pic2',
      gif: 'icon-coms-pic2',
      common: 'icon-coms-Enclosure',
    };
    return (
      <div className="wea-doc-news-detail">
        <div className="detail-date">{content.doclastmoddate}</div>
        <div className="detail-docsubject wea-f16">{content.docsubject}</div>
        <div className="detail-content">
          <span dangerouslySetInnerHTML={{ __html: content.doccontent }} />
        </div>
        <div className="detail-attachList">
          {
            bool && <div className="attachList-title">附件下载：</div>
          }
          {
            bool && attachListCon.map((v) => {
              const label = v.name.substring(v.name.indexOf('.') + 1).toLowerCase();
              return (
                <div className="attachList-outer">
                  <a href={`/weaver/weaver.file.FileDownload?fileid=${v.fileid}`} className="attachList-single">
                    <span className={`${labels[label]} attachList-icon`} />
                    <span>{v.name}</span>
                    <span className="icon-coms-download" />
                  </a>
                </div>
              );
            })
          }
        </div>
      </div>
    );
  }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@nwysoa`} msg={props.error ? props.error : getLabel(385218, '对不起，该页面异常，请联系管理员！')} />,
  { error: '' },
)(Main);

